package com.test.google.app.domain;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;

import com.google.appengine.api.datastore.Key;

@Entity
public class File implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key key;
	
	private String name;
	
	private String path;
	
	private long size;
	
	private String mimeType;
	
	@Lob
	@Basic(fetch=FetchType.LAZY)
	@Column(columnDefinition="BLOB")
	private byte[] content;
	
	private String createTime;

	public File() {
	}
	
	public File(Key key) {
		this.key = key;
	}
	
	public String getDir() {
		if (path != null) {
			String s = path.substring(0, path.lastIndexOf("/"));
			return s.equals("") ? "/" : s;
		}
		return "";
	}

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public String getMimeType() {
		return mimeType;
	}

	public void setMimeType(String mimeType) {
		this.mimeType = mimeType;
	}

	public byte[] getContent() {
		return content;
	}

	public void setContent(byte[] content) {
		this.content = content;
	}

	public String getCreateTime() {
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

}
